<?php
$page_title = 'eTAT: Preview Survey';
$style = 'survey';
$script = 'survey';
require_once '../controller.php';
require_once '../header.php';
if(isset($params->sid)) {
	$survey = $instructor->getSurvey($params->sid );
} else {
	redirect('survey/');
}
if(isset($params->sec)) {
	$sec = $params->sec;
} else {
	redirect('survey/' );
}
if(isset($params->num)) {
	$q_num = $params->num;
} else {
	redirect('survey/' );
}
print '<h1>'.anchor('survey/','Surveys',array('noselect'=>false)).' > '.$survey->survey_name.' Preview</h1>';
echo '<div id="preview">';
echo "<h1 align='center'>$survey->survey_title</h1>";
if($sec == 1) {
	echo "<p align='center'>$survey->welcome_message</p>";
}
$questions = $survey->getAllQuestions ();
if($questions) {
echo '( Questions marked <font color="red" size="5">*</font> are required )<br><br>';
	$size = sizeof($questions);
	$num = $q_num - $sec + 2;
	foreach($questions as $i=>$q) {
		$type = $q->type;
		$required = $q->required;
		$question = $q->question;
		$create_section = $q->create_section;
		$order = $q->order;
		$response1 = $q->response1;
		$response2 = $q->response2;
		$response3 = $q->response3;
		$response4 = $q->response4;
		$response5 = $q->response5;
		$response6 = $q->response6;
		if($q_num < $i || $q_num == $i) {
			if($create_section == "Y" && $i != $q_num) {
				$sec++;
				$q_num = $i;
				if ($sec > 2) {
					echo "<div id='back'><input type='button' onclick='history.go(-1)' Value='Back'></div>";
				}
				echo "<div id='next'><input type='submit' value='next' onclick='change($survey->id,$sec,$q_num)'></div>";
				break;
			}
			if ($type == 'section') {
				echo '<p align="center">' . $question . '</p><br>';
				$num --;
			} elseif ($type == 'text') {
				if ($required == 'Y')
					echo '<font color="red" size="5">*</font>';
				echo '<b>' . $num . '. ' . $question . '</b><br>';
				echo '<input type="text" size = "50px"><br>';
			} elseif ($type == 'date' || $type == 'numeric') {
				if ($required == 'Y')
					echo '<font color="red" size="5">*</font>';
				echo '<b>' . $num . '. ' . $question . '</b><br>';
				echo '<input type="text" size = "15px"><br>';
			} elseif ($type == 'yesno') {
				if ($required == 'Y')
					echo '<font color="red" size="5">*</font>';
				echo '<b>' . $num . '. ' . $question . '</b><br>';
				echo '<input type="radio">Yes<br>';
				echo '<input type="radio">No<br>';
			} elseif ($type == 'checkbox') {
				if ($required == 'Y')
					echo '<font color="red" size="5">*</font>';
				echo '<b>' . $num . '. ' . $question . '</b><br>';

				if ($response1 != '')
					echo '<input type="checkbox">' . $response1 . '<br>';
				if ($response2 != '')
					echo '<input type="checkbox">' . $response2 . '<br>';
				if ($response3 != '')
					echo '<input type="checkbox">' . $response3 . '<br>';
				if ($response4 != '')
					echo '<input type="checkbox">' . $response4 . '<br>';
				if ($response5 != '')
					echo '<input type="checkbox">' . $response5 . '<br>';
				if ($response6 != '')
					echo '<input type="checkbox">' . $response6 . '<br>';
			} elseif ($type == 'radio') {
				if ($required == 'Y')
					echo '<font color="red" size="5">*</font>';
				echo '<b>' . $num . '. ' . $question . '</b><br>';

				if ($response1 != '')
					echo '<input type="radio">' . $response1 . '<br>';
				if ($response2 != '')
					echo '<input type="radio">' . $response2 . '<br>';
				if ($response3 != '')
					echo '<input type="radio">' . $response3 . '<br>';
				if ($response4 != '')
					echo '<input type="radio">' . $response4 . '<br>';
				if ($response5 != '')
					echo '<input type="radio">' . $response5 . '<br>';
				if ($response6 != '')
					echo '<input type="radio">' . $response6 . '<br>';
			} elseif ($type == 'dropdown') {
				if ($required == 'Y')
					echo '<font color="red" size="5">*</font>';
				echo '<b>' . $num . '. ' . $question . '</b><br>';
				echo '<select>';
				if ($response1 != '')
					echo '<option>' . $response1 . '</option>';
				if ($response2 != '')
					echo '<option>' . $response2 . '</option>';
				if ($response3 != '')
					echo '<option>' . $response3 . '</option>';
				if ($response4 != '')
					echo '<option>' . $response4 . '</option>';
				if ($response5 != '')
					echo '<option>' . $response5 . '</option>';
				if ($response6 != '')
					echo '<option>' . $response6 . '</option>';
				echo '</select><br>';
			} elseif ($type == 'rate') {
				if ($required == 'Y')
					echo '<font color="red" size="5">*</font>';
				echo '<b>' . $num . '. ' . $question . '</b><br>';
				echo '<table>';

				echo '<tr><td width="70px">Value</td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td></tr>';
				if ($response1 != '')
					echo '<tr><td width="70px">' . $response1 . '</td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td></tr>';
				if ($response2 != '')
					echo '<tr><td width="70px">' . $response2 . '</td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td></tr>';
				if ($response3 != '')
					echo '<tr><td width="70px">' . $response3 . '</td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td></tr>';
				if ($response4 != '')
					echo '<tr><td width="70px">' . $response4 . '</td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td></tr>';
				if ($response5 != '')
					echo '<tr><td width="70px">' . $response5 . '</td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td></tr>';
				if ($response6 != '')
					echo '<tr><td width="70px">' . $response6 . '</td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td><td><input type ="radio"></td></tr>';
				echo '</table><br>';
			}
			echo '<br>';
			$num ++;
		}
		if ($size == $i + 1) {
			if ($sec > 1) {
				echo "<div id='back'><input type='button' onclick='history.go(-1)' Value='Back'></div>";
			}
			echo "<div id='next'><input type='button' value='Submit Survey' onclick='history.go(-$sec)'></div>";
		}
	}
	print "<div class='clear'></div>";
}
?>
</div>
<div class='clear'></div>
<?php
require_once '../footer.php';
?>